﻿<%@ Page Language="C#" AutoEventWireup="true" Debug="true" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase, Microsoft.SharePoint"%>
<%@ Import Namespace="Microsoft.SharePoint.Administration"%>
<%@ Import Namespace="SharePointOfView.SPReporting"%>
<%@ Import Namespace="SharePointOfView.SPReporting.Jobs"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Register TagPrefix="SoV" Namespace="SharePointOfView.SPReporting" Assembly="SharePointOfView.SPReporting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=85a56337686e234b" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server"><asp:Literal ID="litPageTitle" runat="server" /></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server"><asp:Literal ID="litPageTitle2" runat="server" /></asp:Content>
<asp:Content id="Breadcrumb" contentplaceholderid="PlaceHolderTitleBreadcrumb" runat="server">
<asp:HyperLink ID="hlSite" runat="server" /> &gt; <asp:HyperLink ID="hlSiteSettings" runat="server" Text="<%$Resources:wss,settings_pagetitle %>" /> &gt; <asp:Label CssClass="ms-sitemapdirectional" ID="lbCurrentPage" runat="server" />
</asp:Content>
<asp:Content ID="PageDescription" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
SharePoint of View - SPReporting on CodePlex : <a href="http://sovspreporting.codeplex.com/" target="_blank">Home (Wiki)</a>, <a href="http://sovspreporting.codeplex.com/Release/ProjectReleases.aspx#ReleaseFiles" target="_blank">Downloads</a>, <a href="http://sovspreporting.codeplex.com/Thread/List.aspx" target="_blank">Discussions</a>, <a href="http://sovspreporting.codeplex.com/WorkItem/List.aspx" target="_blank">Issue Tracker</a>
<br /><br />
<asp:HyperLink ID="hlBackToLibrary" runat="server" />
</asp:Content>
<asp:Content ID="MainContent" ContentPlaceHolderId="PlaceHolderMain" runat="server">
<div>
<asp:Literal ID="litVersioning" runat="server" /> [<asp:HyperLink ID="hlVersioningStatus" runat="server" />] (Major : <asp:Literal ID="litMajorVersions" runat="server" />)
</div>
<SharePoint:MenuTemplate ID="mtMenu" runat="server">
    <SharePoint:MenuItemTemplate ID="mitDisplayReport" runat="server" Text="DisplayReport" ImageUrl="/_layouts/images/GRA16.gif" ClientOnClickNavigateUrl="Report.aspx?rid=%ID%" Title="DisplayReport"></SharePoint:MenuItemTemplate>
    <SharePoint:MenuItemTemplate ID="mitDetails" runat="server" Text="Details" ImageUrl="/_layouts/images/detail.gif" ClientOnClickNavigateUrl="?id=%ID%" Title="Details"></SharePoint:MenuItemTemplate>
    <SharePoint:MenuItemTemplate ID="mitEditModel" runat="server" Text="Edit" ImageUrl="/_layouts/images/edit.gif" ClientOnClickNavigateUrl="?id=%ID%" Title="Edit"></SharePoint:MenuItemTemplate>
</SharePoint:MenuTemplate>
<SharePoint:SPGridView id="gvReportModels" runat="server" AutoGenerateColumns="false" AllowSorting="false">
    <Columns>
        <SharePoint:SPMenuField 
            HeaderText="Title" 
            TextFields="Title" 
            MenuTemplateId="mtMenu" 
            NavigateUrlFields="Id" 
            NavigateUrlFormat="Report.aspx?rid={0}" 
            TokenNameAndValueFields="ID=Id"
            />
        <SharePoint:SPBoundField DataField="ReportSource" HeaderText="ReportSource" />
    </Columns>
</SharePoint:SPGridView>
</asp:Content>
<script runat="server">
    protected override void OnLoad(EventArgs e)
    {
        hlSite.Text = SPContext.Current.Web.Title;
        hlSite.NavigateUrl = SPContext.Current.Web.Url;
        hlSiteSettings.NavigateUrl = SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, "/_layouts/settings.aspx");

        if (!Page.IsPostBack)
        {
            LocalizeControls();
            SPFeature reportingFeature = SPContext.Current.Web.Features[Globals.SPReportingWebFeatureId];
            if (reportingFeature != null)
            {
                string listReportModelsUrl = Utilities.GetResourceString("SoVSPReportingLists_ReportingModelsList_Url") + "/Forms/AllItems.aspx";
                string listReportsUrl = Utilities.GetResourceString("SoVSPReportingLists_ReportingReportsList_Url") + "/Forms/AllItems.aspx";

                SPList reportModelsList = SPContext.Current.Web.GetListFromUrl(SPUrlUtility.CombineUrl(SPContext.Current.Web.ServerRelativeUrl, listReportModelsUrl)) as SPDocumentLibrary;
                SPList reportsList = SPContext.Current.Web.GetListFromUrl(SPUrlUtility.CombineUrl(SPContext.Current.Web.ServerRelativeUrl, listReportsUrl)) as SPDocumentLibrary;

                hlBackToLibrary.NavigateUrl = reportModelsList.DefaultViewUrl;

                if (!Page.IsPostBack)
                {
                    mitDetails.ClientOnClickNavigateUrl = SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, string.Format("{0}{1}", reportModelsList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url, "?ID=%ID%"));
                    
                    if (reportsList.EnableVersioning)
                    {
                        hlVersioningStatus.Text = Utilities.GetResourceString("SoVSPReportingWeb_Versioning_Enabled");
                        litMajorVersions.Text = reportsList.MajorVersionLimit.ToString();
                    }
                    else
                    {
                        hlVersioningStatus.Text = Utilities.GetResourceString("SoVSPReportingWeb_Versioning_Disabled");
                        litMajorVersions.Text = "-";
                    }
                    
                    hlVersioningStatus.NavigateUrl = SPUrlUtility.CombineUrl(SPContext.Current.Web.ServerRelativeUrl, "/_layouts/LstSetng.aspx?List=" + reportsList.ID.ToString() + "&Source=" + HttpUtility.UrlEncode(this.Request.Url.OriginalString));
                }

                BindData(reportModelsList.Items.GetDataTable());
            }
        }
        
        base.OnLoad(e);
    }

    void LocalizeControls()
    {
        string pageTitle = string.Format("{0} - {1}", Utilities.GetResourceString("SoVSPReporting_SoVGroup"), Utilities.GetResourceString("SoVSPReporting_ReportingAdmin_Title"));
        litPageTitle.Text = litPageTitle2.Text = pageTitle;
        lbCurrentPage.Text = Utilities.GetResourceString("SoVSPReporting_ReportingAdmin_Title");
        hlBackToLibrary.Text = Utilities.GetResourceString("SoVSPReportingWeb_GoToReportModelsDocLib");
        mitDetails.Text = mitDetails.Title = Utilities.GetResourceString("SoVSPReporting_ReportingAdmin_Details");
        mitEditModel.Text = mitEditModel.Title = Utilities.GetResourceString("SoVSPReporting_ReportingAdmin_EditModel");
        mitDisplayReport.Text = mitDisplayReport.Title = Utilities.GetResourceString("SoVSPReporting_ReportingAdmin_DisplayReport");
        litVersioning.Text = Utilities.GetResourceString("SoVSPReportingWeb_Versioning");

        foreach(DataControlField field in gvReportModels.Columns)
        {
            field.HeaderText = Utilities.GetResourceString(string.Format("SoVSPReporting_ReportingAdmin_Header_{0}", field.HeaderText));
        }
    }

    void BindData(DataTable dtModels)
    {
        gvReportModels.DataSource = dtModels;
        gvReportModels.DataBind();
    }
</script>